package org.neframework.webtest.interceptor.login;

import java.io.IOException;
import java.lang.reflect.Method;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.neframework.webtest.model.t_fk_user;
import org.neframework.webtest.util.web.session.SessionTools;

import com.tmsps.neframework.mvc.annotation.RequestMapping;
import com.tmsps.neframework.mvc.core.NeBaseController;
import com.tmsps.neframework.mvc.web.interceptor.Interceptor;

/**
 * 分页拦截器，定义拦截路径 /cp
 * 
 * @author uninf
 * 
 */
@RequestMapping("/cp")
public class LoginInterceptor implements Interceptor {

	@Override
	public boolean before(NeBaseController action, Method method, HttpServletRequest request, HttpServletResponse response) {
		t_fk_user login_user = (t_fk_user) SessionTools.getCurrentLoginAdmin(request);

		if (login_user == null) {
			try {
				response.sendRedirect(request.getContextPath() + "/relogin.htm");
				return false;
			} catch (IOException e) {
				e.printStackTrace();
			}
		}

		return true;
	}

	@Override
	public boolean after(NeBaseController action, Method method, HttpServletRequest request, HttpServletResponse response) {
		// TODO Auto-generated method stub
		return true;
	}

}
